package com.xiaogang.ggfw.utils.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 返回对象
 *
 * @author 相小维
 * @date 2021/8/19
 */
@ApiModel("APIRs")
public class APIRs<T> {

    @ApiModelProperty("状态号")
    private Integer code;
    @ApiModelProperty("消息")
    private String msg;
    @ApiModelProperty("响应data")
    private T data;

    public static final int code_success = 200;//请求成功x
    public static final int code_success_data_err = 201;//请求数据错误(针对第三方请求)
    public static final int code_success_deal_err = 202;//请求处理错误
    public static final int code_forbidden = 403;//请求拒绝
    public static final int code_fail = 500;//请求失败
    public static final int code_dev_non_exist = 501;//智能柜不存在
    public static final int code_refund = 1101;//=错误，需要退件
    public static final int code_paramerror = 1001;//=参数错误
    public static final int code_tokenerror = 1002;//=token为空
    public static final int code_tokenout = 1003;//token过期
    public static final int code_params_updatederr = 1010;//参数不可修改，已修改过

    /********签名********/
    public static final int code_sign_error = 2001;//签名格式错误
    public static final int code_sign_timeout = 2002;//签名过期
    public static final int code_sign_empty = 2003;//签名不存在
    public static final int code_signkey_err = 2004;//签名key不存在
    /********签名********/

    public static final String failMsg = "api.fail";
    public static final String successMag = "api.success";

    public APIRs() {

    }

    public APIRs(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public APIRs(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public APIRs(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> ok() {
        return new APIRs<>(code_success, successMag);
    }

    /**
     * 成功消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> ok(String msg) {
        return new APIRs<>(code_success, msg);
    }

    /**
     * 成功消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> ok(String msg, T data) {
        return new APIRs<>(code_success, msg, data);
    }

    /**
     * 成功消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> okData(T data) {
        return new APIRs<T>(code_success, successMag, data);
    }

    public static <T> APIRs<T> okData() {
        return new APIRs<T>(code_success, successMag, null);
    }

    /**
     * 失败消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> fail() {
        return new APIRs<>(code_fail, failMsg);
    }

    /**
     * 失败消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> fail(String msg) {
        return new APIRs<>(code_fail, msg);
    }

    /**
     * 失败消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> fail(String msg, T data) {
        return new APIRs<>(code_fail, msg, data);
    }

    /**
     * 失败消息
     *
     * @author 相小维
     * @date 2021/8/19
     */
    public static <T> APIRs<T> fail(T data) {
        return new APIRs<>(code_fail, failMsg, data);
    }

    public static APIRs failTokenErr() {
        return new APIRs(code_tokenerror, "token错误", null);
    }

    public static APIRs failTokenErr(String msg) {
        return new APIRs(code_tokenerror, msg, null);
    }

    /**
     * describe：自定义
     *
     * @author XiangXiaoWei
     * date 2022/2/22
     */
    public static <T> APIRs<T> custom(Integer code, String msg) {
        return new APIRs<>(code, msg);
    }

    /**
     * describe：自定义
     *
     * @author XiangXiaoWei
     * date 2022/2/22
     */
    public static <T> APIRs<T> custom(Integer code, String msg, T data) {
        return new APIRs<>(code, msg, data);
    }

    public static APIRs signError() {
        return new APIRs(code_sign_error, "签名格式错误", null);
    }

    public static APIRs signTimeout() {
        return new APIRs(code_sign_timeout, "签名过期", null);
    }

    public static APIRs signEmpty() {
        return new APIRs(code_sign_empty, "签名不存在", null);
    }

    public static APIRs signKeyError() {
        return new APIRs(code_signkey_err, "签名key不存在", null);
    }


    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

}
